#!/bin/bash
# author
# Usage Docker 24.0.7
set -e

# Docker  24.0.7
docker_ver=${1:-"24.0.7"}


# install Docker
function docker_install(){
	mkdir -p /data/docker
	curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
	sed -i 's#https://download.docker.com#https://mirrors.tuna.tsinghua.edu.cn/docker-ce#' /etc/yum.repos.d/docker-ce.repo
	sed -i 's#$releasever#7#g' /etc/yum.repos.d/docker-ce.repo
	yum remove docker-ce-${docker_ver} docker-ce-cli-${docker_ver} docker-ce-rootless-extras-${docker_ver} containerd.io docker-buildx-plugin docker-compose-plugin -y
	yum install docker-ce-${docker_ver} docker-ce-cli-${docker_ver} docker-ce-rootless-extras-${docker_ver} containerd.io docker-buildx-plugin docker-compose-plugin -y
	cat > /etc/docker/daemon.json <<- EOF
	{
  	"data-root": "/data/docker",
  		"registry-mirrors": [
  		"https://registry.hub.docker.com",
  		"https://mirror.baidubce.com",
    	"https://hub-mirror.c.163.com",
    	"https://docker.mirrors.ustc.edu.cn"
  	],
  	"log-opts": {
    	"max-size": "10m",
    	"max-file":"3"
  	},
  	"storage-driver": "overlay2",
  	"exec-opts": ["native.cgroupdriver=systemd"]
	}
	EOF

	# start service && enable service
	systemctl enable docker --now
}

# function docker_check(){
#   docker info
# }


docker_install
# docker_check